<template>
  <div id="home">
    <el-container class="home-container">
      <el-aside :width="foldFlag ? '64px' : '200px'">
        <span class="juzao-name">ORDER聚造</span>
        <span class="foldMenuButton" @click="foldMenu">|||</span>

        <el-menu
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          :collapse="foldFlag"
          :collapse-transition="false"
          background-color="#2c2c2c"
          text-color="#fff"
          :router="true"
          active-text-color="#ffd04b"
        >
          <el-submenu index="1"> 
            <template slot="title">  
            <i class="el-icon-s-home"></i>
            <span>首页管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item :index="'banner'">轮播图管理</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item :index="'category'">分类区管理</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item :index="'recomened'">为您推荐管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-s-shop"></i>
              <span>商品管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item :index="'Classifiedmanagement'">分类管理</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item :index="'Brandmanagement'">品牌管理</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item :index="'Commoditymanagement'">商品管理</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item :index="'Singleproduct'">单品管理</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-s-comment"></i>
              <span>商场管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item :index="'article'">新闻管理</el-menu-item>
            </el-menu-item-group>
            <el-menu-item-group>
              <el-menu-item :index="'test'">111</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-menu-item :index="'PersonalManagement'">
        <i class="el-icon-user-solid"></i>
        <span slot="title" >个人中心</span>
      </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <b>{{$route.meta.title}}</b>
          <div class="user">
            <!-- 头像 -->
            <el-avatar class="ava" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"  ></el-avatar>
            <span class="title">{{shownickName}}</span>
            <span class="userName" >{{showuserName}}</span>
            <span class="sayHello">您好!</span>
            <el-button
              @click="logOut"
              type="danger"
              icon="el-icon-switch-button"
              round
              >退出</el-button
            >
            <!-- <i class="el-icon-edit-outline" @click="personalForm"></i> -->
          </div>
        </el-header>
        <el-main>
          <!-- 路由占位符号 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import Cookies from 'js-cookie'



export default {
  name:'home',
  data() {
    return {
      userName:'',
      foldFlag: false, //展开
      // circleUrl:
      //   // "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
      //   "https://img2.woyaogexing.com/2022/04/13/7f9775fc6e4245e98e64eb84e44e029b!400x400.jpeg",
    };
  },
  created() {
    
  },
  
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    // personalForm(){
    //   this.$router.push('/personalManagement')
    // },
    logOut(){
      this.$confirm("是否退出登录","提示",{
        confirmButtonText:"确定",
        cancelButtonText:"取消",
        type:"warning",
      }).then(() => {
        this.$http({
          url:"/admin/logout",
        }).then((res) => {
          if(res.errorMsg) {
            this.$message.error(res.errorMsg);
          }else{
            localStorage.removeItem('token')
            localStorage.removeItem('user')
            location.href = "/login"
          }
        })
      })
    },
    //折叠aside
    foldMenu() {
      this.foldFlag = !this.foldFlag;
    },
    // login() {
    //   //执行登录操作，登录成功跳转到home页面
    //   // console.log("登录操作");
    //   this.$router.push({
    //     path:'/home'
    //   })
    // }
  },
  computed:{
    showuserName(){
      return Cookies.get('token')
  },
    shownickName(){
      // return JSON.stringify(localStorage.getItem('user'))
      return localStorage.getItem('user');
      }
    }
}
</script>

<style>
#home {
  height: 100%;
}
.home-container {
  height: 100%;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  line-height: 100px;
  height: 100px !important;
}

.el-aside {
  background-color: #2c2c2c;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.juzao-name {
  margin-left: 30px;
  width: 100px;
  height: 23px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  color: #ffffff;
  font-weight: normal;
  font-size: 20px;
}
.foldMenuButton {
  font-size: 20px;
  width: 12px;
  height: 1px;
  border-radius: 1px 1px 1px 1px;
  opacity: 1;
  color: #fff;
  cursor: pointer;
  float: right;
  margin-right: 10px;
}

/* 侧边栏 */
.el-menu-vertical-demo {
  margin-top: 30px;
  border-right: none;
}

.el-icon-arrow-right {
  color: #333;
}
.el-breadcrumb {
  line-height: 100px;
  font-size: 20px;
  color: #333;
}
/* 头像 */
.user {
  /* width: 370px; */
  display: flex;
  align-items: center;
  float: right;
}
.ava{
  width:51px;
  height: 51px;
  /* position: absolute; */
  top: 27px;
  left: 897px;
  /* margin-top: 32px;
  margin-left:897px; */
}
.title {
  padding-left: 10px;
  padding-right: 10px;
  color: orange;
}
.sayHello {
  padding-right: 15px;
}
.el-icon-edit-outline{
  margin-left: 10px;
}
</style>